<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Master extends CI_Controller {

	function test(){
		$a=$this->mod_master->mskpd();

		echo json_encode($a);
	}

	function Vuser(){
		$data=array('form'=>'MASTER USER');
		$this->template->set('title','.: e-Disposisi | User :.');
		$this->template->load('index','master/user',$data);	
        //$this->load->view('master/user',$data);
	}

	function listuser(){
		$param=$this->input->post('param');		

		$hasil  ="";		
		$hasil .="
				<table class='table table-bordered table-striped' style='width:400px'>
						<thead>
							<th>USER</th>
							<th>NAMA LENGKAP</th>
						</thead>
						<tbody>
				";
		$user=$this->mod_master->duser($param);
		$jum=count($user);
		foreach($user as $val){
			$nm=$val->nmuser;
			$hasil .="												
					<tr>
						<td>".$val->nmuser."</td>
						<td>".$val->nama_lengkap."</td>
						<td width='5%' align='center'><a href='#' onclick='lihatdata(\"$nm\")'><img src='".base_url()."img/checkmark.png' width='30' height='30' border='0' alt=''></td>
					</tr>
					";
		}											

		$hasil .="		
					</tbody>
				</table>
		";

		$coba=array('isi'=>$hasil,'rec'=>$jum);
        echo json_encode($coba);
	}

	function lihatuser(){
		$param=$this->input->post('param');		
		$user =$this->mod_master->duser($param,'1');
		foreach($user as $val){
			$nm =$val->nmuser;
			$nml=$val->nama_lengkap;
			$kdskpd=$val->kdskpd;
		}
		$coba=array(
					'user'=>$nm,
					'nama'=>$nml,
					'skpd'=>$kdskpd
			       );
		echo json_encode($coba);
	}

	function simpanuser(){
		$user=$this->input->post('user');		
		$pass=md5($this->input->post('pass'));		
		$nama=$this->input->post('nama');		
		$skpd=$this->input->post('skpd');
		$iduser=md5($user);
        $query = $this->db->query(" delete from muser where nmuser='$user' ");  
        $query = $this->db->query(" insert into muser(iduser,password,nmuser,nama_lengkap,kdskpd) values('$iduser','$pass','$user','$nama','$skpd') ");  
		$coba  = array('hasil'=>'Data Tersimpan');
        echo json_encode($coba);		
	}

	function hapususer(){
		$user  = $this->input->post('user');		
        $query = $this->db->query(" delete from muser where nmuser='$user' ");  
		$coba  = array('hasil'=>'Data Terhapus');
        echo json_encode($coba);		
	}

}

